﻿using AutoMapper;
using DataModels.User;
using DataServices.User.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataServices.User
{
    /// <summary>
    /// 用户数据服务类
    /// </summary>
    public class Plan2UserService : IuserService
    {
        /// <summary>
        /// 自动映射实体对象接口
        /// </summary>
        private IMapper _mapper;

        /// <summary>
        /// 构造注入mapper
        /// </summary>
        /// <param name="mapper"></param>
        public Plan2UserService(IMapper mapper) {

            this._mapper= mapper;
        }

        //模拟数据，可以用自行实现数据库查询 
        #region 模拟数据，可以用自行实现数据库查询
        public List<UserEntity> _UserList = new List<UserEntity>()
        {
            new UserEntity{
                Id=1001,
                CreateTime=DateTime.Now,
                UpdateTime=DateTime.Now,
                _Age=19,
                _LoginId="1001",
                _Name="小1",
                _PhoneNum="13098776222",
                _Pwds="1234567",
            },
            new UserEntity{
                Id=1002,
                CreateTime=DateTime.Now,
                UpdateTime=DateTime.Now,
                _Age=19,
                _LoginId="1002",
                _Name="小2",
                _PhoneNum="13098776224",
                _Pwds="1234567",
            },
            new UserEntity{
                Id=1003,
                CreateTime=DateTime.Now,
                UpdateTime=DateTime.Now,
                _Age=19,
                _LoginId="1003",
                _Name="小3",
                _PhoneNum="13098776225",
                _Pwds="1234567",
            },
        };
        #endregion

        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public UserSearchOutput UserSearch(UserSearchInput input)
        {
            //get List by input
            var result = _UserList.Where(s=>s._Name==input._UserName).ToList();

            //var result = _UserList;

            List<UserDto> userList = _mapper.Map<List<UserDto>>(result);

            return new UserSearchOutput()
            {
                UserList = userList
            };
        }

    }
}
